package com.usian.controller;

import com.usian.pojo.Emp;
import com.usian.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@RequestMapping("login")
@Controller
public class LoginController {
    @Autowired
    private EmpService empService;
    @RequestMapping("login")
    public String login(HttpSession session, Emp emp, Model model){
        if (emp!=null && emp.getName()!=null && emp.getPwd()!=null){
            Emp emp1=empService.login(emp);
            if (emp1!=null){
                session.setAttribute("emp",emp1);
                return "redirect:/emp/findAll?type="+emp1.getType()+"&did="+emp1.getDid();
            }else {
                return "login";
            }
        }
        return "login";
    }
}
